﻿using System;
using System.Collections.Generic;
using System.Text;
using EmbeddedSharp;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Core.Function.String {

    /// <summary>
    /// The compare function is case senstive
    /// compare("hello", "hello"); # true
    /// 
    /// compare("hello", "Hello"); # false
    /// 
    /// use 1 for the 3rd parameter to ignore the casing compare
    /// compare("hello", "Hello", 1); # true
    /// </summary>
    [Function("Compare", "Compare if the two strings are identical", "compare(\"hello\", \"hello\");", "true")]
    public class CompareNode : FuncNode {

        public CompareNode()
            : base() {
            base.Value = "compare";
        }

        public override object Evaluate() {
            if (Parameters.Count < 2) {
                throw new ArgumentException(
                    "Usage: compare(strA, strB[, {1}]");
            }

            string left = Parameters[0].Evaluate().ToString();
            string right = Parameters[1].Evaluate().ToString();

            return left.CompareTo(right);
        }
    }
}
